#include"PushBackRect.h"

/////////////////
//include
/////////////////
#include"Game.h"
#include<ANX\Mouse.h>
/////////////////
//prottype
/////////////////

/////////////////
//const
/////////////////

PushBackRect::PushBackRect()
{
	edit_rect = EditRect();
	line = Line2D();

}
PushBackRect::~PushBackRect()
{
}

void PushBackRect::Init()
{
	edit_rect.Init();
	edit_rect.SetStartPos(Vector2D(100,100));
	edit_rect.SetEndPos(Vector2D(-100,-100));
	rect = Rect(edit_rect.GetStartPos().x,EditRect().GetStartPos().y,RECT_SIZE,RECT_SIZE);
	rect2 = Rect(edit_rect.GetEndPos().x,EditRect().GetEndPos().y,RECT_SIZE,RECT_SIZE);
}
void PushBackRect::ContentLoad(Device* device)
{
	edit_rect.ContentLoad();
}
void PushBackRect::Update()
{
	pre_pos = rect2.GetPos();
	edit_rect.Update();
	rect.SetPos(edit_rect.GetStartPos());
	rect2.SetPos(edit_rect.GetEndPos());

	if(rect.CollisionPos(rect2 ,rect2.GetPos(), pre_pos) != Vector2D::GetWrongParameter())
	{
		rect2.SetPos( rect.CollisionPos(rect2 ,rect2.GetPos(),pre_pos) );
		edit_rect.SetEndPos(rect2.GetPos());
	}


	
}
void PushBackRect::Draw(DeviceContext* device_context)
{
	Game::sprite_drawer->DrawRect(rect);
	Game::sprite_drawer->DrawRect(rect2);
	Game::sprite_drawer->DrawRect(Rect(Mouse::GetPos().ChengeScreenPos().x,Mouse::GetPos().ChengeScreenPos().y,RECT_SIZE,RECT_SIZE));




	Game::sprite_drawer->DrawRect(Rect(line.start,line.end));
//	Game::sprite_drawer->DrawRect(Rect(line2.start,line2.end));
	//Vector2D tmp_mouse_pos = Mouse::GetPos().ChengeScreenPos();
	//Game::sprite_drawer->DrawRect(Rect(tmp_mouse_pos.x,tmp_mouse_pos.y,RECT_SIZE,RECT_SIZE));
	//printf("x = %f,y = %f\n",tmp_mouse_pos.x,tmp_mouse_pos.y);
}